#@adminLayout()

#define adminMain()
<section class="content">
	<div class="row">
		<div class="col-md-12">
          <!-- general form elements -->
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">添加用户</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form role="form" id="reg-form" method="post" action="/admin/account/addUser">
              <div class="box-body">
                <div class="form-group">
                  <label for="exampleInputEmail1">输入邮箱</label>
                  <input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" required>
                </div>
                <div class="form-group">
                  <label for="exampleInputEmail1">输入用户名</label>
                  <input type="text" name="userName" class="form-control" id="exampleInputEmail1" placeholder="Enter user name" required>
                </div>
                <div class="form-group">
                  <label for="exampleInputEmail1">输入昵称</label>
                  <input type="text" name="nickName" class="form-control" id="exampleInputEmail1" placeholder="Enter nickName" required>
                </div>
                <div class="form-group">
                  <label for="exampleInputPassword1">输入密码</label>
                  <input type="password" name="password" class="form-control" id="exampleInputPassword1" placeholder="Password" minlength="6" maxlength="20" required>
                </div>
                <div class="form-group">
                  <label for="exampleInputPassword2">输入密码</label>
                  <input type="password" name="rePassword" class="form-control" id="exampleInputPassword2" placeholder="Password" minlength="6" maxlength="20" required>
                </div>
              </div>
              <!-- /.box-body -->

              <div class="box-footer">
                <button type="submit" class="btn btn-primary">添加用户</button>
              </div>
            </form>
          </div>
          <!-- /.box -->
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->

        </div>
	</div>
</section>
#end

#define js()
<script type="text/javascript" src="/assets/jquery_form/jquery.form.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#reg-form").ajaxForm({
			dataType: "json"
			, beforeSubmit: function(formData, jqForm, options) {     
				// 表单提交之前回调                                 
				// do nothing
			}
			, success: function(ret) {
				console.log("ret:"+ret);
				// 业务层验证成功
				if(ret.isOk) {
					layer.msg(ret.msg, {
								icon: 6
								, shift: 6
								, shade: 0.3
								, time: 8500
								, offset: "165px"
								, closeBtn: 1
								, shadeClose: true
							}, function() {
								//跳转到首页
								window.location.href="/admin/account/list";
							}
					);
					return ;
				}
				
				// 业务层验证失败
				if (ret.isFail) {
					layer.msg(ret.msg, {
								shift: 6
								, shade: 0.3
								, time: 8500
								, offset: "165px"
								, closeBtn: 1
								, shadeClose: true
							} , function() {
								//暂时不加验证码
								//updateCaptcha();
							}
					);
					return ;
				}
				
				// Validator 层验证失败
				if (ret.emailMsg) {
					layer.msg(ret.emailMsg, {
								icon: 5
								, shift: 6
								, shade: 0.3
								, time: 8500
								, offset: "165px"
								, closeBtn: 1
								, shadeClose: true
							}
					);
				}
				if (ret.userNameMsg) {
					layer.msg(ret.userNameMsg, {
								icon: 5
								, shift: 6
								, shade: 0.3
								, time: 8500
								, offset: "165px"
								, closeBtn: 1
								, shadeClose: true
							}
					);
				}
				if (ret.passwordMsg) {
					layer.msg(ret.passwordMsg,  {
								icon: 5
								, shift: 6
								, shade: 0.3
								, time: 8500
								, offset: "165px"
								, closeBtn: 1
								, shadeClose: true
							}
					);
				}
			}
			, error: function(ret) {console.log("error") }              // ret.status != 200 时回调
			, complete: function(ret) {console.log("complete")  }       // 无论是 success 还是 error，最终都会被回调
		});
	});
	//暂时不用
	/*
	function updateCaptcha() {
		$(".captcha").attr("src", "/reg/captcha?v=" + Math.random());
		$("#captchaInput").val("");
	}*/
</script>
#end
